import request from '../utils/request';
import qs from 'qs';
let host = "http://127.0.0.1:8000";

export async function query(params) {
    return request(`${host}/rest/user/?${qs.stringify(params)}`, {
        method: 'get',
        headers: {
            "Authorization": "Token " + localStorage.getItem('authToken')
        },
    });
}

export async function update(params) {
    return request(`${host}/rest/user/${params.id}/`, {
        method: 'put',
        body: qs.stringify(params),
        headers: {
            "Authorization": "Token " + localStorage.getItem('authToken'),
            "Content-Type": "application/x-www-form-urlencoded"
        },
    });
}

export async function create(params) {
    return request(`${host}/rest/user/`, {
        method: 'post',
        body: qs.stringify(params),
        headers: {
            "Authorization": "Token " + localStorage.getItem('authToken'),
            "Content-Type": "application/x-www-form-urlencoded"
        },
    });
}

export async function remove(params) {
    return request(`${host}/rest/user/${params.id}/`, {
        method: 'delete',
        headers: {
            "Authorization": "Token " + localStorage.getItem('authToken'),
        },
    });
}
